/* 
 * Copyright 2011 kOSMik.
 * This file is part of kOSMik.
 * 
 * kOSMik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * kOSMik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * kOSMik:
 * Open Street Map - Editor.
 * http://code.google.com/p/swp-dv-ws2010-osm-2/
 */

package plugin;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.gui.layer.markerlayer.ButtonMarker;
import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;

/**
 * VideoButtonMarker extends the JOSM - class ButtonMarker to show
 * kOSMik - captured video files (.mp4).
 * 
 * @author Andreas
 */
public class VideoButtonMarker extends ButtonMarker{
	
	private URL videoUrl;

	/**
	 * Constructor.
	 * @param ll contains coordinate latitude and longitude.
	 * @param text - (unimportant).
	 * @param url Video file.
	 * @param parentLayer The parent layer.
	 * @param time Time stamp of POI (Point of Interest)
	 * @param offset Offset.
	 */
	public VideoButtonMarker(LatLon ll, String text, URL videoUrl,
			MarkerLayer parentLayer, double time, double offset) {
		super(ll, text, "icon_video.png", parentLayer, time, offset);
		this.videoUrl = videoUrl;
	}
	
	/**
	 * Creates an VideoButtonMarker object with the specified values.
	 * @param ll contains coordinate latitude and longitude.
	 * @param text - (unimportant)
	 * @param url Video file.
	 * @param parentLayer The parent layer.
	 * @param time Time stamp of POI (Point of Interest)
	 * @param offset Offset.
	 * @return An VideoButtonMarker.
	 */
	public static VideoButtonMarker create(LatLon ll, String text, String url, MarkerLayer parentLayer, double time, double offset){
		try{
			return new VideoButtonMarker(ll, text, new URL(url), parentLayer, time, offset);
		} catch(Exception e){
			return null;
		}
	}
	
	@Override
	public void actionPerformed(ActionEvent actionEvent){
		Desktop desktop = Desktop.getDesktop();
		try {
			desktop.open(new File(videoUrl.toURI()));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
	}

}
